<template>
  <div class="color-picker-container">
    <!-- 颜色选择器输入框 -->
    <input
      type="color"
      :value="modelValue"
      @input="handleColorChange"
      class="color-input"
    />
  </div>
</template>

<script>
import { defineComponent } from "vue";

export default defineComponent({
  name: "ColorPicker",
  props: {
    modelValue: {
      type: String,
      default: "#ffffff",
    },
  },
  emits: ["update:modelValue", "color-selected"],
  setup(props, { emit }) {
    const handleColorChange = (event) => {
      const newValue = event.target.value;
      emit("update:modelValue", newValue);
      emit("color-selected", newValue);
    };

    return {
      handleColorChange,
    };
  },
});
</script>

<style scoped>
.color-picker-container {
  position: relative;
}

.color-input {
  cursor: pointer;
}

.color-info {
  position: absolute;
  bottom: 40px;
  left: 0;
  background-color: white;
  padding: 10px;
  border-radius: 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  z-index: 10;
}

.color-preview {
  width: 100px;
  height: 50px;
  border: 1px solid #ccc;
  border-radius: 3px;
  margin-bottom: 5px;
}

.color-value {
  font-size: 0.9em;
}

/* 添加过渡动画 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s;
}
.fade-enter,
.fade-leave-to {
  opacity: 0;
}
</style>
